package com.alittle.module;


import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.ViewFlipper;

import com.alittle.R;
import com.alittle.core.ALBaseMvpActivity;
import com.alittle.mvp.func.IPanelHostPresenter;
import com.alittle.mvp.func.IPanelHostView;

import dev.xesam.androidkit.utils.ViewUtil;

/**
 * Created by wom on 2015/8/17.
 */
public class PanelHostActivity extends ALBaseMvpActivity<IPanelHostPresenter> implements IPanelHostView, CompoundButton.OnCheckedChangeListener {

    ViewFlipper viewFlipper;
    RadioButton homeworkBtn, gradeBtn, noticeBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.parents_main_panelhost);

        viewFlipper = ViewUtil.findById(this, R.id.parents_main_view_flipper);
        homeworkBtn = ViewUtil.findById(this,R.id.parents_main_homework_btn);
        gradeBtn = ViewUtil.findById(this,R.id.parents_main_grade_btn);
        noticeBtn = ViewUtil.findById(this,R.id.parents_main_notice_btn);

        homeworkBtn.setOnCheckedChangeListener(this);
        gradeBtn.setOnCheckedChangeListener(this);
        noticeBtn.setOnCheckedChangeListener(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        presenter.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        presenter.onPause();
    }
    //Todo TooolBar的处理
    @Override
    protected boolean isDisplayHomeAsUpEnabled() {
        return false;
    }

    @Override
    protected IPanelHostPresenter createPresenter() {
        return new PanelHostPresenter(this);
    }

    @Override
    public void showDefaultPage() {
        homeworkBtn.setChecked(true);
    }

    @Override
    public void changeChild() {
        //Todo something
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if (!isChecked) {//不处理 unchecked 状态
            return;
        }
        if (buttonView == homeworkBtn) {
            viewFlipper.setDisplayedChild(0);
        } else if (buttonView == gradeBtn) {
            viewFlipper.setDisplayedChild(1);
        } else {
            viewFlipper.setDisplayedChild(2);
        }
    }


}
